package com.haiqi.modules.map.service;

import com.haiqi.common.persistence.dao.CompanyWarningMapper;
import com.haiqi.common.persistence.entity.CompanyWarning;
import com.haiqi.common.utils.DateUtils;
import com.haiqi.common.utils.UUIDGenerator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by hythzx on 2016/6/28.
 */

@Service
public class CompanyWarningService {

    @Autowired
    private CompanyWarningMapper companyWarningMapper;

    public boolean save(CompanyWarning companyWarning){
        boolean success = false;
        int i = 0;
        if(StringUtils.isNotEmpty(companyWarning.getGuid())){  //编辑
            i = companyWarningMapper.updateByPrimaryKeySelective(companyWarning);
        }else{  //添加
            companyWarning.setGuid(UUIDGenerator.getUUID());
            companyWarning.setPublishtime(DateUtils.dateToString(new Date(),DateUtils.DATETIME_FORMAT));
            companyWarning.setNtype("2");
            companyWarning.setState("0");
             i = companyWarningMapper.insert(companyWarning);
        }
        if(i > 0){
            success = true;
        }
        return success;
    }

    public boolean delete(CompanyWarning companyWarning){
        boolean success = false;
        int i = companyWarningMapper.deleteByPrimaryKey(companyWarning.getGuid());
        if(i > 0){
            success = true;
        }
        return success;
    }

    public List<CompanyWarning> getDataList(CompanyWarning companyWarning){
        List<CompanyWarning> companyWarnings = companyWarningMapper.select(companyWarning);
        return companyWarnings;
    }


}
